#include <string.h>
#include "HAL_conf.h"
#include "BSP.h"
#include "iwdg.h"
#include "mg_api.h"




unsigned char *ble_mac_addr;

const unsigned char AdvDat_HRS[]=
{
    0x02,0x01,0x06,
    0x03,0x19,0x41,0x03,
    0x07,0x03,0x0D,0x18,0x0A,0x18,0x0F,0x18
};

int main(void)
{
    unsigned long temp=0x20000;
    unsigned char *ft_val1 = (unsigned char *)(0x1FFFF804);
    unsigned char ft_value[2] = {0xc0, 0x12};

    while(temp--);//wait a while for hex programming if using the MCU stop mode, default NOT used.
    
    BSP_Init();
    SetBleIntRunningMode();
    radio_initBle(TXPWR_0DBM, &ble_mac_addr);
    radio_setCal_nonBlocking(1);
    ble_set_adv_data((unsigned char *)AdvDat_HRS, sizeof(AdvDat_HRS));

    if((*ft_val1 > 11) && (*ft_val1 < 27)){
        ft_value[1] = *ft_val1;
        mg_activate(0x53);
        mg_writeBuf(0x4, ft_value, 2);
        mg_activate(0x56);
    }

    Write_Iwdg_ON(IWDG_Prescaler_64, 4000);
    
    ble_run_interrupt_start(160*2);  //320*0.625=200 ms
    while(1){
        IrqMcuGotoSleepAndWakeup();
        
        //user proc
    }
}
